function createProductContainer()
{
    if(!dijit.byId('productBorderContainer'))
    {
        var bc = new dijit.layout.BorderContainer({
            id:'productBorderContainer',
            design:'sidebar',
            gutters:true,
            liveSplitters:true,	
            style:'border: 0px; height: 400px;' 
        });
        
        var center = new dijit.layout.ContentPane({id: "bcProductForm", region: "center", splitter: true, style:"padding: 0px;"});
        bc.addChild(center);
        
        var top = new dijit.layout.ContentPane({id: "bcProductGrid", region: "top", splitter: true, style:"padding: 0px; height:200px;"});
        bc.addChild(top);
        
        top.set('content', 'top');
        center.set('content', 'top');
        
        bc.startup();
        bc.layout();
        
        var myCenter= dijit.byId("myCenter");
        myCenter.set('content', bc);
    }
}

function getProductForm()
{
    if(!dijit.byId('addressForm'))
    {   
        dojo.xhrGet({
            url:"index.php/product/product/edit",
            handleAs:"text",
            load: function(data){
    //            console.log(data);
                dijit.byId("bcProductForm").set('content', data);
                initUploader();
            }   
        });

        dojo.parser.parse(dojo.byId('bcProductForm'));
        
    }
}

function onProductGridClick(e)
{
    var item = e.grid.getItem(e.rowIndex);
    var price = new String(item.product_price);
    
    item.product_price = price.replace('.', ',');
    dijit.byId('productForm').set('value', item);
}

function refreshProductGrid()
{
    var store = new dojo.data.ItemFileWriteStore({
        url: 'index.php/product/product/list?format=json'
    });
    
    var grid = dijit.byId("gridProduct");
    grid.setStore(store);
    
}

function saveData()
{
    dojo.xhrPost({
        url: 'index.php/product/product/edit?format=json',
        form: 'productForm',
        load: function(data){
            refreshProductGrid();
        }
    });
    
}
function openProduct()
{
    createProductContainer();
    getProductForm();
    
    
    
    var store = new dojo.data.ItemFileWriteStore({
        url: 'index.php/product/product/list?format=json'
    });
    var layout = [
		    {'name': '#', 'field': 'product_id', 'width': '20px'},
		    {'name': 'No', 'field': 'product_internalnumber', 'width': '50px'},
		    {'name': 'Name', 'field': 'product_name', 'width': '200px'},
                    {'name': 'Preis', 'field': 'product_price', 'width': '50px'},
		    
		];
    var grid = dijit.byId("gridProduct");
    if(!grid)
    {
        grid = new dojox.grid.DataGrid({
            id: 'gridProduct',
            store: store,
            structure: layout,
            rowSelector: '20px'},
            document.createElement('div')
        );
        dojo.connect(grid, 'onRowClick', 'onProductGridClick');
        dijit.byId("bcProductGrid").set( 'content', grid.domNode );
        dijit.byId("productBorderContainer").resize();
        grid.startup();
       
    }
     
        
//        var item = grid.getItem(0);
//
//        dijit.byId('productForm').set('value', item);

    
}